package algorithm_study.leecode;

public class Jump {
    int jump;
    int res;
    public int jump(int[] nums) {
        if(nums.length==1){
            return 0;
        }
        if(nums.length==2){
            return 1;
        }
        res=Integer.MAX_VALUE;
        jump=0;
        myjump(0,nums);
        return res+1;
    }
    public void myjump(int pos,int[]nums){
        //跳跃次数+1
        jump++;
        int n=nums[pos];
        for(int i=1;i<=n;i++){
            if(pos+i==n-1){
                if(jump<res){
                    res=jump;
                }
                jump--;
                return;
            }
            if(pos+i>=n){
                jump--;
                return;
            }
            myjump(pos+i,nums);
        }
    }

    public static void main(String[] args) {
          int[]nums={2,3,1,1,4};
          new Jump().jump(nums);
    }
}
